package co.edu.uniandes.mdd.project1.sample.util;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Properties;

public class PropertiesLoader {
	
	private String PACMAN_PROP_PATH = "C:/MDD/runtime-project1wspc/co.edu.uniandes.mdd.project1.sample/src/co/edu/uniandes/mdd/project1/sample/properties/pacman.properties";
	private String GHOSTS_PROP_PATH			= "C:/MDD/runtime-project1wspc/co.edu.uniandes.mdd.project1.sample/src/co/edu/uniandes/mdd/project1/sample/properties/ghosts.properties";
	private String BLOCKS_PROP_PATH 		= "C:/MDD/runtime-project1wspc/co.edu.uniandes.mdd.project1.sample/src/co/edu/uniandes/mdd/project1/sample/properties/blocks.properties";
	private String DOTS_PROP_PATH 			= "C:/MDD/runtime-project1wspc/co.edu.uniandes.mdd.project1.sample/src/co/edu/uniandes/mdd/project1/sample/properties/pellets.properties";
	private String POWER_PELLETS_PROP_PATH 	= "C:/MDD/runtime-project1wspc/co.edu.uniandes.mdd.project1.sample/src/co/edu/uniandes/mdd/project1/sample/properties/power_pellets.properties";
	
	private static Properties pacmanProperties;
	private static Properties ghostsProperties;
	private static Properties blocksProperties;
	private static Properties labProperties;
	private static Properties dotsProperties;
	private static Properties powerPelletsProperties;
	
	public PropertiesLoader () {		
		FileInputStream in = null;
			
		try {
			if (pacmanProperties == null) {
				pacmanProperties = new Properties();
				in = new FileInputStream(PACMAN_PROP_PATH);				
				pacmanProperties.load(in);
			}
			if (ghostsProperties == null) {
				ghostsProperties = new Properties();
				in = new FileInputStream(GHOSTS_PROP_PATH);
				ghostsProperties.load(in);
			}			
			if (blocksProperties == null) {
				blocksProperties = new Properties();
				in = new FileInputStream(BLOCKS_PROP_PATH);
				blocksProperties.load(in);
			}	
			if (dotsProperties == null) {
				dotsProperties = new Properties();
				in = new FileInputStream(DOTS_PROP_PATH);
				dotsProperties.load(in);
			}	
			if (powerPelletsProperties == null) {
				powerPelletsProperties = new Properties();
				in = new FileInputStream(POWER_PELLETS_PROP_PATH);
				powerPelletsProperties.load(in);
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	public String getPacmanProperty (String key) {
		return pacmanProperties.getProperty(key);
	}
	
	public String getGhostProperty (String key) {
		return ghostsProperties.getProperty(key);
	}
	
	public String getBlockProperty (String key) {
		return blocksProperties.getProperty(key);
	}
	
	
	public String getDotProperty (String key) {
		return dotsProperties.getProperty(key);
	}
	
	public String getPowerPelletProperty (String key) {
		return powerPelletsProperties.getProperty(key);
	}
}
